import request from '@/utils/request';
import Constants from '@/utils/constants';

/** 获取列表 POST  */
export async function entityPage(params: any,tableName:String, options?: { [key: string]: any }) {
  return request<API.BaseRes>(`${Constants.SERVICE_ROOT}/curd/${tableName}/page`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
    ...(options || {}),
  });
}


/** 获取详情 GET  */
export async function entityInfo(tableName:String,params: any) {
  return request<API.BaseRes>(`${Constants.SERVICE_ROOT}/curd/${tableName}/info`, {
    method: 'GET',
    params: {
      ...params,
    },
  });
}


/** 更新 PUT */
export async function entityUpdate(tableName:String,params:any) {
  return request<API.BaseRes>(`${Constants.SERVICE_ROOT}/curd/${tableName}/info`, {
    method: 'PUT',
    data: {
      ...params,
    },
  });
}

/** 删除 DELETE */
export async function entityDel(tableName:String,params:any) {
  return request<API.BaseRes>(`${Constants.SERVICE_ROOT}/curd/${tableName}/info`, {
    method: 'DELETE',
    data: {
      ...params,
    },
  });
}


/** 新建 POST */
export async function entityAdd(tableName:String,params:any) {
  return request<API.BaseRes>(`${Constants.SERVICE_ROOT}/curd/${tableName}/info`, {
    method: 'POST',
    data: {
      ...params,
    },
  });
}


/** 获取配置Json GET  */
export async function getJsonConfig(tableName:String) {
  return request<API.BaseRes>(`/${tableName}`, {
    method: 'GET',
  });
}
